package com.mudrov.realization;

import java.util.NoSuchElementException;

import com.mudrov.collections.realization.LinkedListForQueue;
import com.mudrov.interfaces.Queue;

public class LinkedListQueue<E> extends LinkedListForQueue<E> implements Queue<E>{
	
	@Override
	public E element() {
		if(size == 0)
			throw new NoSuchElementException();
		return head.element;
	}

	@Override
	public boolean offer(E e) {
		this.add(e);
		return true;
	}

	@Override
	public E peek() {
		if(size == 0)
			return null;
		return head.element;
	}

	@Override
	public E poll() {
		if(size == 0)
			return null;
		E toReturn = head.element;
		head = head.next;
		--size;
		return toReturn;
	}

	@Override
	public E remove() {
		if(size == 0)
			throw new NoSuchElementException();
		E toReturn = head.element;
		head = head.next;
		--size;
		return toReturn;
	}

}
